package com.yy.jhl.ui.manager.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yy.common.base.BaseActivity;
import com.yy.common.commonwidget.OnNoDoubleClickListener;
import com.yy.jhl.R;
import com.yy.jhl.bean.FunctionInfo;
import com.yy.jhl.bean.UpdateInfo;
import com.yy.jhl.ui.manager.contract.FunctionContract;
import com.yy.jhl.ui.manager.presenter.FunctionPresenter;
import com.yy.jhl.util.DeviceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by libingn on 2018/2/9.
 */

public class AboutUsActivity extends BaseActivity<FunctionPresenter> implements FunctionContract.View {
    @BindView(R.id.version_code_text)
    TextView versionCodeText;
    @BindView(R.id.function_introduce_parent)
    LinearLayout functionIntroduceParent;
    @BindView(R.id.kefu_parent)
    LinearLayout kefuParent;
    @BindView(R.id.version_update_parent)
    LinearLayout versionUpdateParent;
    @BindView(R.id.version_tag)
    ImageView unreadImage;

    @Override
    public int getLayoutId() {
        return R.layout.act_about_us;
    }

    @Override
    public void initView() {
        showTitle("关于我们", new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
        versionCodeText.setText(DeviceUtil.getVersion(mContext));
    }

    @Override
    protected void onStart() {
        super.onStart();
        mPresenter.updateApk(false);
    }

    @OnClick({R.id.function_introduce_parent, R.id.kefu_parent, R.id.version_update_parent})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.function_introduce_parent:
                startActivity(FunctionIntroduceActivity.class);
                break;
            case R.id.kefu_parent:
                break;
            case R.id.version_update_parent:
                mPresenter.updateApk(true);
                break;
        }
    }

    @Override
    public void getSuccess(FunctionInfo projectInfo) {

    }

    @Override
    public void getUpdateApkSuccess(boolean isShow, UpdateInfo projectInfo) {
            String serverApkVersion = projectInfo.getCurrent().replaceAll("\\.", "");
            String currentApkVersion = getString(R.string.version_name).replaceAll("\\.", "");
            try {
                if (Integer.parseInt(serverApkVersion) > Integer.parseInt(currentApkVersion)) {
                    if (isShow){
                        Intent intent = new Intent();
                        intent.setAction("android.intent.action.VIEW");
                        Uri content_url = Uri.parse("http://static.jiaohuilian.com/psw/common/down");
                        intent.setData(content_url);
                        startActivity(intent);
                    }else {
                        unreadImage.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (isShow){
                        showShortToast("暂无新版本");
                    }else {
                        unreadImage.setVisibility(View.GONE);
                    }
                }

            }catch (Exception e){

            }
    }

    @Override
    public void getFail() {

    }
}
